// const db=wx.cloud.database();     //获取数据库的引用
import { get } from "../../utils/db"
Page({
  data: {
    list: [],
    page: 1,     //页面
    pageSize: 10,    //每页条数
  },
  async onLoad() {
    // let result =await db.collection("users").where({}).get()
    let result = await get({ collection: "users", where: {}, skip: 0, limit: 10 }).catch(err => {
      console.log(err)
    })
    this.setData({
      list: result.data
    })
  },
  //页面触底加载更多
  async onReachBottom() {
    this.data.page++;
    // this.data.page=this.data.page+1;
    // let page=this.data.page;
    // let pageSize=this.data.pageSize;
    let { page, pageSize } = this.data
    let skip = (page - 1) * pageSize;
    //获取最新一页的内容
    let result = await get({ collection: "users", skip: skip, limit: pageSize }).catch(err => {
      console.log(err)
    })
    //新一页的内容和上一页的内容进行拼接
    let list=this.data.list.concat(result.data)
    //把拼接后的数据，都渲染到页面
    this.setData({
      list
    })
  }

})